﻿#pragma once
#pragma execution_character_set("utf-8")

#include <QGraphicsView>
#include <QScrollBar>
#include "ItemBase.h"

class QLabel;
class QMouseEvent;
class GraphicsScene;
class ImageItem;

class GraphicsView : public QGraphicsView
{
	Q_OBJECT

public:
    GraphicsView(QWidget* parent = nullptr);
    void dispImage(const QImage& Image); //显示图片
    void setType(bool InfoFlg, bool lblGrayValueFlg);//设定显示信息
    void showMsg(const QString& msg);
    QImage getImage(){return mImg;}

    void addItem(ItemBase* item); //添加ROI
    void removeItem(ItemBase* item); //移除ROI
    void removeSelected(); //移除ROI
    void clearItem();
    ItemBase* getSelectItem();

    void addRegionList(QVector<QVector<QPointF> > &list, QColor color = QColor(0, 255, 0));
    void addXldList(QVector<QVector<QPointF> > &list, QColor color = QColor(0, 255, 0));
    void clearDraw();

public:
    GraphicsScene* scene;
    ItemDraw* drawItem;
    ImageItem* itemImg;
    QList<ItemBase*> itemList;

protected:
	virtual void mousePressEvent(QMouseEvent* event) override;
	virtual void mouseReleaseEvent(QMouseEvent* event) override;
	virtual void mouseDoubleClickEvent(QMouseEvent* event) override;
	virtual void mouseMoveEvent(QMouseEvent* event) override;
	virtual void wheelEvent(QWheelEvent* event) override;
	virtual void resizeEvent(QResizeEvent* event) override;
	virtual void drawBackground(QPainter* painter, const QRectF& rect) override;
	virtual void paintEvent(QPaintEvent* event) override;
	virtual void contextMenuEvent(QContextMenuEvent* event) override;   //右键菜单

private:
	void onZoomInImage();
	void onZoomOutImage();
	void onFitImage();
	void zoomFrame(double value);
	void getFit();
    void drawBg();
    void setToFit(qreal val);

private:
	double zoomValue = 1;
	double zoomFit = 1;
	double pixX = 0;
	double pixY = 0;
    QImage mImg;
	QLabel* lblGrayValue; //显示灰度值
	QLabel* lblOtherMsg;//信息显示
	QColor color1 = QColor(30, 30, 30);           //颜色1
    QColor color2 = QColor(50, 50, 50, 255);      //颜色2
	QPixmap bgPix = QPixmap(36, 36);              //背景图片
};
